#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

int main ()
{
    struct timespec timeout;
    struct timeval  tp_before, tp_after;
    ::gettimeofday (&tp_before, NULL);
    sleep (2);
    ::gettimeofday (&tp_after, NULL);
    int escape_usec = tp_after.tv_usec - tp_before.tv_usec;
    int escape_sec  = tp_after.tv_sec  - tp_before.tv_sec;
    if (escape_usec < 0)
    {
	escape_sec  -= 1;
	escape_usec += 1000000;
    }
    int escape_msec  = escape_sec * 1000 + escape_usec / 1000;
    printf ("escape msec = %d \n", escape_msec);
    return 0;
}
